<?php
// 本类由系统自动生成，仅供测试用途
class DtupAction extends Action {

	
	//预设  para一般自身的所有以及扩展的zabojingua东西
	//聚合
    private $all=array(
    	'mdmk'=>'Dtup',//NB
  		'ttl'=>'数据上传',
  		'jn'=>array('tb_type ON f_dtup_typeid=typeid'),//NB
      //自己的全部+f的显示的东西
  		'para'=>array('dtupid'=>'dtupID','f_dtup_typeid'=>'类型','typenm'=>'类型','typemoney'=>'金额(元)','dtupqyqqno'=>'帐号','dtupqyqqpw'=>'密码','dtupuptm'=>'上传时间','dtupusrqqno'=>'用户个人QQ号','dtupalipayno'=>'支付宝订单号','dtuptiqutm'=>'用户提取时间','dtupstat'=>'是否提取'),//NB
  		//抛去不是zabojin的属性针对para
      'notself'=>array('typenm','typemoney'),
       ##########modify 添加修改中不需要展示和理会的属性 针对para
      'no_update'=>array('dtupid','dtupuptm','dtuptiqutm','typenm','typemoney','dtupstat'),
      #####update的时候允许为空的值 针对zabojin刨掉不然显示的update字段后
      'allowempty'=>array('dtupusrqqno','dtupalipayno','dtupusrqqno'),

      'hide_fld'=>array('dtupid','f_dtup_typeid'),//NB
      'hide_cdt'=>array('dtupid','typenm','typemoney'),//NB
  		
    //   'spccdtls'=>array('spccdt_0'=>array('dtupid<>0','dtupID不为0【废话只是测试】')),
  		// 'odrls'=>array('dtupnm'),
    //   'spccdt_dflt'=>array('spccdt_0'),
    //   'odr_dflt'=>array('dtupnm'=>'ASC'),

      'spccdtls'=>array(),//NB
      'odrls'=>array('dtupuptm','dtupid'),//NB
      'spccdt_dflt'=>array(),//NB
      'odr_dflt'=>array('dtupuptm'=>'DESC','dtupid'=>'ASC'),//NB
      //hide的fld必须有，他们虽然不显示但是必须选择，这样才能在第一次进入query的时候，隐藏属性可以被调用，特别是id和fid
  		'fld_dflt'=>array('dtupid','typenm','typemoney','dtupqyqqno','dtupqyqqpw','dtupuptm','dtupusrqqno','dtupalipayno','dtuptiqutm','dtupstat'),//NB
  		'cdt_dflt'=>array(),//NB
  		
  		'lmt_dflt'=>50,//NB
  		
  		'defaultls'=>1,//默认枚举//NB
  		##########view
  		'no_view'=>array('dtupid'),
	   
      #########删除提醒
      'deleteconfirm'=>'确定要删除此条记录？',
      #####转义
      'transmean'=>array('dtupstat'=>array('0'=>'否','1'=>'是')),//NB
      #####默认值
      'dfltvalue'=>array('dtupstat'=>0),
      
    );

    //公版
    public function query(){
    	header("Content-Type:text/html; charset=utf-8");
    	$pb=D('PB');$type=D('Type');
    	$pb->query($this->all);
      
      //重新覆盖类型让类型有金额提示
      $arr_typels=$type->getmlsorderbymoneydesc();$typels=$arr_typels['data'];
      $typelsnw=array();
      foreach($typels as $typev){
        $typev['typenm']=$typev['typenm'].'(￥'.$typev['typemoney'].')';
        array_push($typelsnw, $typev);
      }
      $this->assign('f_dtup_typeid',$typelsnw);

      $this->display('query');

  
    }
    
    //公版
    public function view(){
    	header("Content-Type:text/html; charset=utf-8");
    	$pb=D('PB');
    	$pb->view($this->all);
		  $this->display('Cmn:view');
    }
   
   	//公版
   	public function update(){
   		header("Content-Type:text/html; charset=utf-8");
    	$pb=D('PB');
    	$pb->update($this->all);
		  $this->display('update');
   	}

   	//公版
   	public function doupdate(){
   		header("Content-Type:text/html; charset=utf-8");
   		$dtup=D('Dtup');
   		$arr_pattern=$dtup->doupdate($this->all);
   		$data['pattern']=$arr_pattern['pattern'];

   		$this->ajaxReturn($data,'json');
   	}

   	//公版
   	public function dodelete(){
   		header("Content-Type:text/html; charset=utf-8");
   		$pb=D('PB');
   		$pb->dodelete($this->all);
  		
   		$this->ajaxReturn($data,'json');
   	}

    //公版
    public function fenxidaoru(){
      header("Content-Type:text/html; charset=utf-8");
      $dtup=D('Dtup');$type=D('Type');
      
      $rslt=1;//默认是正常的
      $tail=session('tail');
      if(!($tail=='xls'||$tail=='xlsx')){
        $rslt=2;//文件格式不正确
      }else{
        //如果格式没问题，就开始读取数据了
        import('@.ORG.PHPExcel');
        //设定缓存模式为经gzip压缩后存入cache（PHPExcel导入导出及大量数据导入缓存方式的修改 ）
        $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip;
        $cacheSettings = array();
        PHPExcel_Settings::setCacheStorageMethod($cacheMethod,$cacheSettings);
    
        $objPHPExcel = new PHPExcel();
        // $con = mysql_connect("localhost","root","123456");
        // mysql_select_db('bms');
        //读入上传文件
        $myfl=session('myfl');$myfl=str_replace('/'.C('PROJECT'),'.',$myfl);
        //$objPHPExcel = PHPExcel_IOFactory::load($_FILES["inputExcel"]["tmp_name"]);
        $objPHPExcel = PHPExcel_IOFactory::load($myfl);
         
        $currentSheet = $objPHPExcel->getSheet(0);// 当前页
        $row_num = $currentSheet->getHighestRow();// 当前页行数
        $col_max = $currentSheet->getHighestColumn(); // 当前页最大列号

        $arr_error=Array();
        $tongji_success=0;
        $tm=date('Y-m-d H:m:s',time());
        for($i = 2; $i <= $row_num; $i++){
            
            
            $ads = 'A' . $i; // 单元格坐标address
            $dtupqyqqno = trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
            $ads = 'B' . $i; // 单元格坐标address
            $dtupqyqqpw=trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
            $ads = 'C' . $i; // 单元格坐标address
            $typenm=trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value

            //验证是否本行为空
            if(!$dtupqyqqno){continue;}

            //验证是否重传
            $arr_dtupls=$dtup->getdtuplsbydtupqyqqno($dtupqyqqno);$dtupls=$arr_dtupls['data'];
            if($dtupls){
              $rslt=3;
              $dt['dtupqyqqno']=$dtupqyqqno;
              $dt['dtupqyqqpw']=$dtupqyqqpw;
              $dt['typenm']=$typenm;
              $dt['beizhu']='此卡密已经上传过了';
              array_push($arr_error, $dt);
              continue;
            }

            //验证类型是否正确
            $arr_typeo=$type->getmobytypenm($typenm);$typeo=$arr_typeo['data'];
            if(!$typeo){
              $rslt=3;
              $dt['dtupqyqqno']=$dtupqyqqno;
              $dt['dtupqyqqpw']=$dtupqyqqpw;
              $dt['typenm']=$typenm;
              $dt['beizhu']='类型不正确';
              array_push($arr_error, $dt);
              continue;
            }


            //都过关了先++，然后把数据搞进去
            $tongji_success++;

            $dt['f_dtup_typeid']=$typeo['typeid'];
            $dt['dtupqyqqno']=$dtupqyqqno;
            $dt['dtupqyqqpw']=$dtupqyqqpw;
            $dt['dtupuptm']=$tm;
            $dt['dtupstat']=0;
            $dt['dtupusrqqno']='';
            $dt['dtupalipayno']='';
            $dt['dtuptiqutm']='';
            $dtup->add($dt);
            
        }
      }

      if($rslt==3){
        $data['arr_error']=$arr_error;
      }
      $data['rslt']=$rslt;
      $data['tongji_success']=$tongji_success;

      $this->ajaxReturn($data,'json');
    }

}